package com.my.event.utils;

import cn.hutool.core.util.ObjectUtil;
import com.my.core.domain.log.LogAbstract;
import com.my.core.util.WebUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * @author timo 2021/2/25
 */
public class LogAbstractUtil {
    public LogAbstractUtil() {
    }

    public static void addRequestInfoToLog(HttpServletRequest request, LogAbstract logAbstract) {
        if (ObjectUtil.isNotEmpty(request)) {
            logAbstract.setRemoteIp(WebUtil.getIP(request));
            logAbstract.setUserAgent(request.getHeader("user-agent"));
//            logAbstract.setRequestUri(UrlUtil.getPath(request.getRequestURI()));
            logAbstract.setMethod(request.getMethod());
//            logAbstract.setParams(WebUtil.getRequestContent(request));
//            logAbstract.setCreateBy(AuthUtil.getUserAccount(request));
        }
    }
//    public static void addOtherInfoToLog(LogAbstract logAbstract, BladeProperties bladeProperties, ServerInfo serverInfo) {
//        logAbstract.setServiceId(bladeProperties.getName());
//        logAbstract.setServerHost(serverInfo.getHostName());
//        logAbstract.setServerIp(serverInfo.getIpWithPort());
//        logAbstract.setEnv(bladeProperties.getEnv());
//        logAbstract.setCreateTime(DateUtil.now());
//        if (logAbstract.getParams() == null) {
//            logAbstract.setParams("");
//        }
//    }
}
